{% extends 'manage.html' %}
{% block title %}
    管理中心
{% endblock %}

{% block css %}
    <style>
        .a1 {
            margin-left: 4.3%;
        }

        .project {
            margin-top: 10px;
        }

        .error-msg {
            color: red;
            position: absolute;
        }

        .card {
            width: 90%;
            margin: 10px auto;
        }

        .card-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .card-body > .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .card-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .card-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .card-body > .item > .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .card-body > .item > .info a {
            text-decoration: none;
        }

        .card-body > .item > .info .fa-star {
            font-size: 18px;
        }
        .color-radio label{
            margin-left: 0;
            padding-left: 0;
        }
        .color-radio input[type='radio']{
            display: none;
        }
        .color-radio input[type='radio'] + .cycle{
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }
        .color-radio input[type='radio']:checked + .cycle{
            border: 2px solid black;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="container-fluid project">
        <a class="btn btn-primary a1" data-toggle="modal" data-target="#addModal">
            <i class="fa fa-plus-circle" aria-hidden="true"></i> 新建项目
        </a>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">新建项目</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="addForm">
                        {% csrf_token %}
                        {% for field in form %}

                            {% if field.name == 'color' %}
                                <div class="form-group">
                                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>

                                    {{ field }}

                                </div>

                            {% else %}
                                <div class="form-group">
                                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                    {{ field }}
                                    <span class="error-msg"></span>
                                </div>
                            {% endif %}
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">确定</button>
                </div>
            </div>
        </div>
    </div>

    <div class="card">
        <h5 class="card-header"><i class="fas fa-star"></i> 星标项目</h5>
        <div class="card-body">
            {% for item in project_dict.star %}
                <div class="item">
                    <a href="{% url 'manage:dashboard' project_id=item.value.id %}" class="title"
                       style="background-color: {{ item.value.get_color_display }}">{{ item.value.name }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">
                                <i class="fas fa-star" style="color: #e5e52a"></i>
                            </a>
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fas fa-users"></i>
                            <span>{{ item.value.join_count }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>

    <div class="card">
        <h5 class="card-header"><i class="fas fa-list"></i> 我创建的项目</h5>
        <div class="card-body">
            {% for item in project_dict.my %}
                <div class="item">
                    <a href="{% url 'manage:dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='my' project_id=item.id %}">
                                <i class="fas fa-star" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fas fa-users"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>

    <div class="card">
        <h5 class="card-header"><i class="fa fa-handshake"></i> 我参加的项目</h5>
        <div class="card-body">
            {% for item in project_dict.join %}
                <div class="item">
                    <a href="{% url 'manage:dashboard' project_id=item.id %}" class="title" style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='join' project_id=item.id %}">
                                <i class="fas fa-star" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fas fa-users"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(function () {
            bindSubmit();
        })

        function bindSubmit() {
            $('#btnSubmit').click(function () {
                //发送ajax请求
                $.ajax({
                    url: '{% url 'project_list' %}',
                    type: 'POST',
                    data: $('#addForm').serialize(),
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status) {
                            location.href = location.href;
                            //location.reload();
                        } else {
                            $.each(res.error, function (key, value) {
                                $('#id_' + key).next().text(value[0])
                            })
                        }
                    }
                })
            })
        }
    </script>
{% endblock %}